package com.gemme.gemme.wode;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.gemme.gemme.BaseActivity;
import com.gemme.gemme.R;
import com.gemme.gemme.manager.DataManager;
import com.gemme.gemme.view.RefreshView;
import com.gemme.gemme.view.SgDDView;
import com.gemme.gemme.view.Topview;
import com.google.android.material.tabs.TabLayout;
import com.jaeger.library.StatusBarUtil;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

//侧滑删除地址
public class TuikuanListActivity extends BaseActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tuikuan_list);
        initTop();
        initView();
        initData();
        initData2();
    }

    private void initData2() {
//        http://47.114.162.17:9999/mall/shoporderdetail/closeMoneyOrder
        String url = DataManager.BaseUrl + "mall/shoporderdetail/closeMoneyOrder";

        HashMap<String, String> headMap = new HashMap<>();
        headMap.put(DataManager.AuthorizationKey,DataManager.getToken(mContext));
        DataManager.toServer2(mContext, url, DataManager.GET_TYPE, "", headMap, new DataManager.GeResponse() {
            @Override
            public void onResponse(String response) {
                try {
                    System.out.println("");
                    DingdanListBean dingdanListBean = JSON.parseObject(response, DingdanListBean.class);
                    List<DingdanListBean.DataBean> data = dingdanListBean.getData();
                    System.out.println("");
                    TuikuanAdapter tuikuanAdapter = new TuikuanAdapter(data);
                    refreshView.setAdapter(tuikuanAdapter);

                }catch (Exception e){

                }
                System.out.println("");
            }
        });
    }

    private void initData() {
        String url = DataManager.BaseUrl_panghu + "mall/shoporderdetail/wholeOrder/"+ "8";

        HashMap<String, String> headMap = new HashMap<>();
        headMap.put(DataManager.AuthorizationKey,DataManager.getToken(mContext));
        DataManager.toServer2(mContext, url, DataManager.GET_TYPE, "", headMap, new DataManager.GeResponse() {
            @Override
            public void onResponse(String response) {
                try {
                    System.out.println("");
                    DingdanListBean dingdanListBean = JSON.parseObject(response, DingdanListBean.class);
                    List<DingdanListBean.DataBean> data = dingdanListBean.getData();
                    System.out.println("");
                    TuikuanAdapter tuikuanAdapter = new TuikuanAdapter(data);
                    refreshView.setAdapter(tuikuanAdapter);

                }catch (Exception e){

                }
                System.out.println("");
            }
        });
    }

    RefreshView refreshView;
    private void initView() {

        refreshView = findViewById(R.id.refreshView);
        refreshView.setLayoutManager(new LinearLayoutManager(this));

    }


    private void initTop() {
//        StatusBarUtil.setColor(this,getResources().getColor(R.color.white_color) );
        StatusBarUtil.setTransparent(this);
//        StatusBarUtil.setTranslucent(this,250);
        Topview topview = findViewById(R.id.topview);
        topview.setContentText("退款/售后");
    }

    public class TuikuanAdapter extends RecyclerView.Adapter<TuikuanAdapter.ViewHolder>{

        private List<DingdanListBean.DataBean> adapterList;

        public TuikuanAdapter(List<DingdanListBean.DataBean> adapterList) {

            this.adapterList = adapterList;
        }

        @NonNull
        @Override
        public TuikuanAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View inflate = LayoutInflater.from(parent.getContext()).
                    inflate(R.layout.item_tuikuan, null);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            inflate.setLayoutParams(layoutParams);
            return new TuikuanAdapter.ViewHolder(inflate);
        }

        @Override
        public void onBindViewHolder(@NonNull TuikuanAdapter.ViewHolder holder, int position) {


            try {
                DingdanListBean.DataBean dataBean = adapterList.get(position);
                holder.sgDDView.setdata(dataBean);
                holder.tv_price.setText("退款成功 ¥"+dataBean.getPaymentMoney()+"元");
                holder.tv_detail.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(mContext, TuikuanDetailActivity.class);
                        intent.putExtra("data",dataBean.getId());
                        startActivity(intent);
                    }
                });
            }catch (Exception e){

            }
        }

        @Override
        public int getItemCount() {
            return adapterList.size();
        }



        public class ViewHolder extends RecyclerView.ViewHolder {
            TextView tv_detail;
            TextView tv_price;
            SgDDView sgDDView;
            public ViewHolder(@NonNull View itemView) {
                super(itemView);
                 tv_detail= itemView.findViewById(R.id.tv_detail);
                sgDDView = itemView.findViewById(R.id.sgDDView);
                tv_price = itemView.findViewById(R.id.tv_price);
            }
        }
    }



}